﻿@using CSF.Utility.Mvc;
@functions {
    protected SiteMapNode GetSubMenuRoot()
    {
        string area = "";
        var values = ViewContext.RouteData.DataTokens;
        if (values.ContainsKey("area"))
        {
            area = Convert.ToString(values["area"]);
        }
        SiteMapNode result = null;
        SiteMapNode root = SiteMap.RootNode;
        var nodes = root.ChildNodes;

        if (ViewContext.RouteData.Values.ContainsKey("appCode"))
        {
            var appCode = Convert.ToString(ViewContext.RouteData.Values["appCode"]);

            foreach (var node in nodes)
            {
                if (((SiteMapNode)node).Description == Convert.ToString(ViewContext.RouteData.Values["appCode"]))
                {
                    nodes = ((SiteMapNode)node).ChildNodes;
                    break;
                }
            }
        }

        foreach (SiteMapNode node in nodes)
        {
            if (UrlUtility.IsStartWithPath(node.Url, "/" + area))
            {
                result = node;
                break;
            }
        }

        return result;
    }

    protected string AppendUrlParameter(string path, string paramname, string paramvalue)
    {
        if (path.Contains('?'))
        {
            path += "&";
        }
        else
        {
            path += "?";
        }
        path += paramname + "=" + paramvalue;
        return path;
    }
}
@helper DisplaySubMenu(SiteMapNode node)
    {
    string sessionId = Request["SessionId"];
    string path = node.Url;
    if (!string.IsNullOrEmpty(sessionId))
    {
        path = AppendUrlParameter(path, "SessionId", sessionId);
    }
    <li class="active"><a href="@Url.Content(path)" class="current">@node.Title</a>
        @if (node.HasChildNodes)
        {
            <ul class="subnavlist">
            @foreach (SiteMapNode subnode in node.ChildNodes)
            {
                path = subnode.Url;
                if (!string.IsNullOrEmpty(sessionId))
                {
                    path = AppendUrlParameter(path, "SessionId", sessionId);
                }
                <li><a href="@Url.Content(path)">@subnode.Title</a></li>
            }
            </ul>
        }
    </li>
}
@{
    SiteMapNode subMenuRoot = GetSubMenuRoot();
}
<div class="navcontainer">
@if (subMenuRoot != null && subMenuRoot.HasChildNodes)
{
    <ul class="navlist">
    @foreach (SiteMapNode node in subMenuRoot.ChildNodes)
    {
        @DisplaySubMenu(node);
    }
@*        <li class="active"><a href="#" class="current">User Account</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a User Account</a></li>
                <li><a href="#">User Accounts</a></li>
                <li><a href="#">Disabled User Accounts</a></li>
            </ul>
        </li>
        <li><a href="#">User Role</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a User Role</a></li>
                <li><a href="#">User Roles</a></li>
                <li><a href="#">Disabled User Roles</a></li>
            </ul>
        </li>
        <li><a href="#">User Log</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">User Sessions</a></li>
                <li><a href="#">User Action Logs</a></li>
            </ul>
        </li>
        <li><a href="#">Customer</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Customer</a></li>
                <li><a href="#">Customers</a></li>
                <li><a href="#">Unapproved Customers</a></li>
                <li><a href="#">Disabled Customers</a></li>
            </ul>
        </li>
        <li><a href="#">Customer Contact</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Customer Contact</a></li>
                <li><a href="#">Customer Contacts</a></li>
            </ul>
        </li>
        <li><a href="#">Customer Type</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Customer Type</a></li>
                <li><a href="#">Customer Types</a></li>
                <li><a href="#">Disabled Customer Types</a></li>
            </ul>
        </li>
        <li><a href="#">Customer User Account</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Customer User Account</a></li>
                <li><a href="#">Customer User Accounts</a></li>
                <li><a href="#">Disapproved Customer User Accounts</a></li>
                <li><a href="#">Disabled Customer User Accounts</a></li>
            </ul>
        </li>
        <li><a href="#">Customer User Role</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Customer User Role</a></li>
                <li><a href="#">Customer User Roles</a></li>
                <li><a href="#">Disabled Customer User Roles</a></li>
            </ul>
        </li>
        <li><a href="#">Region</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Region</a></li>
                <li><a href="#">Regions</a></li>
                <li><a href="#">Disabled Regions</a></li>
            </ul>
        </li>
        <li><a href="#">Terms</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Term</a></li>
                <li><a href="#">Terms</a></li>
                <li><a href="#">Disabled Terms</a></li>
            </ul>
        </li>
        <li><a href="#">Country</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Country</a></li>
                <li><a href="#">Countries</a></li>
                <li><a href="#">Disabled Countries</a></li>
            </ul>
        </li>
        <li><a href="#">Credit Class</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Credit Class</a></li>
                <li><a href="#">Credit Classes</a></li>
                <li><a href="#">Disabled Credit Classes</a></li>
            </ul>
        </li>
        <li><a href="#">Contact Type</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Contact Type</a></li>
                <li><a href="#">Contact Types</a></li>
                <li><a href="#">Disabled Contact Types</a></li>
            </ul>
        </li>
        <li><a href="#">Application</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create an Application</a></li>
                <li><a href="#">Applications</a></li>
                <li><a href="#">Disabled Applications</a></li>
            </ul>
        </li>
        <li><a href="#">Permission</a>
            <ul class="subnavlist">
                <li class="subactive"><a href="#" class="subcurrent">Create a Permission</a></li>
                <li><a href="#">Permissions</a></li>
                <li><a href="#">Disabled Permissions</a></li>
            </ul>
        </li>*@
    </ul>
}
</div>
